﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>call函数实现</title>
</head>
<body>
    <script type="text/javascript">
        Function.prototype.meCall = function () {
            var bindThis = null
            if (arguments.length === 0) {
              bindThis = Object(null)
            } else {
              bindThis = Object(arguments[0])
            }

            let args = []
            if (arguments.length > 1) {
              args = Array.from(arguments).slice(1, arguments.length)
            }
            bindThis.fun = this
            var res = bindThis.fun(...args)
            delete bindThis.fun
            return res
        }

        function doSomething (name, age) {
            console.log(name, age, this)
        }
        doSomething.call({
          hh: 'hh'
        }, 1, 2)
    </script>
</body>
</html>
